<template>
	<div class="container">
		<el-form :model="ruleForm" ref="ruleForm" :rules="rules" :label-position="labelPosition" label-width="120px" class="demo-ruleForm">
			<el-row :span = "22">
				<el-col :span="10">
					<el-form-item label="检测机构：" prop="manageName">
						<el-input placeholder="请输入内容" v-model.trim="ruleForm.manageName" style="width:300px">
							</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="检测负责人：" prop="userName">
						<el-input placeholder="请输入内容" v-model.trim="ruleForm.userName" style="width:300px">
							</el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-form-item class="footerFixed">
			    <el-button type="primary" @click="submitrule('ruleForm')">提交</el-button>
			    <el-button @click="backPage">返回</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>

<script>
	import {manage_save,manage_findById,manage_update} from "@/request/api"
	export default{
		data(){
			return{
				ruleForm:{},
				rules:{
					manageName: [
					    { required: true, message: '不能为空', trigger: 'change' }
					],
					userName: [
					    { required: true, message: '不能为空', trigger: 'change' }
					],
				},
				labelPosition:"right",
				id:'',
                companyId:''
			}
		},
		mounted () {
            this.companyId = this.$route.query.sid
			this.id = this.$route.query.id
			if(this.id == undefined){

			}else{
				this.init()
			}
		},
		methods:{
			init(){
				manage_findById(this.id).then((res)=>{
					this.ruleForm = res.data
				})
			},
			submitrule(formName){
				this.$refs[formName].validate((valid)=>{
				    if(valid){
                        this.ruleForm.companyId = this.companyId
						if(this.id == undefined){
							manage_save(this.ruleForm).then((res)=>{
								this.$notify({
									title: '提示',
									message: '保存成功',
									type: 'success'
								});
								this.backPage()
							})
						}else{
							manage_update(this.ruleForm).then((res)=>{
								this.$notify({
									title: '提示',
									message: '修改成功',
									type: 'success'
								});
								this.backPage()
							})
						}
				        
				    }else{
				        return false
				    }
				})
			},
			backPage(){
				this.$router.go(-1)
			}
		}
	}
</script>

<style scoped>
	
</style>
